﻿Imports Crom.Controls.docking
Imports System.io
Module mdlTrangThaiForm
    Public Function Tim_DockingForm(ByVal DockName As DockContainer) As Form
        Dim Info1 As DockableFormInfo = DockName.GetFormInfo(New Guid("a6402b80-2ebd-4fd3-8930-024a6201d001"))
        Return Info1.DockableForm
    End Function
    Public Function Tim_DockingFormAT(ByVal DockName As DockContainer, ByVal i As Integer) As Form
        Dim Info1 As DockableFormInfo = DockName.GetFormInfoAt(i)
        Return Info1.DockableForm
    End Function
    Public Function Tim_DockingFormBottom(ByVal DockName As DockContainer) As Form
        Dim Info1 As DockableFormInfo = DockName.GetFormInfo(New Guid("0a3f4468-080b-404e-b012-997b93ed2005"))
        Return Info1.DockableForm
    End Function
    Public Sub DockingForm(ByVal result As Form, ByVal DockName As DockContainer)
        CloseFormALL_khac(DockName, result.Name)
        Dim Info1 As DockableFormInfo = DockName.GetFormInfo(New Guid("a6402b80-2ebd-4fd3-8930-024a6201d001"))
        If Info1 Is Nothing Then Info1 = DockName.GetFormInfo(New Guid("0a3f4468-080b-404e-b012-997b93ed2005"))
        result.Bounds = New Rectangle(700, 100, 200, 450)
        Dim info As DockableFormInfo = DockName.Add(result, zAllowedDock.All, New Guid("a6402b80-2ebd-4fd3-8930-024a6201d001"))
        DockName.DockForm(info, Info1, DockStyle.Fill, zDockMode.Inner)
        DockName.SetHeight(info, 310)
    End Sub
    Public Sub CloseFormALL_khac1(ByVal DockName As DockContainer, ByVal frm As String)
        Try
            For i As Integer = 0 To 100
                Dim frm1 As Form = Tim_DockingFormAT(DockName, i)
                If frm1.Name <> frm Then
                    frm1.Close()
                    i = 0
                End If
            Next
        Catch ex As Exception
        End Try
    End Sub
    Public Sub CloseFormALL_khac(ByVal DockName As DockContainer, ByVal frm As String)
        Try
            For i As Integer = 0 To 100
                Dim frm1 As Form = Tim_DockingFormAT(DockName, i)
                If frm1.Name <> frm Then
                    frm1.Close()
                    i = 0
                End If
            Next
        Catch ex As Exception
        End Try
        Try
            CloseForm(frm, DockName)
        Catch ex As Exception
        End Try
    End Sub
    Public Sub CloseForm(ByVal frm As String, ByVal DockName As DockContainer)
        Try
            For i As Integer = 0 To 100
                Dim frmtam As Form = Tim_DockingFormAT(DockName, i)
                If frmtam.Name = frm Then
                    frmtam.Close()
                    Exit Sub
                End If
            Next
        Catch ex As Exception
        End Try
    End Sub
    Public Sub DockRight(ByVal form As Form, ByVal dockName As DockContainer, ByVal mode As System.Windows.Forms.DockStyle)
        Dim Info1 As DockableFormInfo = dockName.GetFormInfo(New Guid("096b52a7-5f4b-44ee-ab77-9830ec717002"))
        form.Bounds = New Rectangle(700, 100, 200, 450)
        Dim info As DockableFormInfo = dockName.Add(form, zAllowedDock.All, New Guid("096b52a7-5f4b-44ee-ab77-9830ec717002"))
        dockName.DockForm(info, Info1, mode, zDockMode.Inner)
        dockName.SetHeight(info, 310)
    End Sub

    Public Sub DockLeft(ByVal form As Form, ByVal dockName As DockContainer, ByVal mode As System.Windows.Forms.DockStyle)
        Dim Info1 As DockableFormInfo = dockName.GetFormInfo(New Guid("3d8466c1-e406-4e47-b744-6915afe6e003"))
        form.Bounds = New Rectangle(700, 100, 250, 450)
        Dim info As DockableFormInfo = dockName.Add(form, zAllowedDock.All, New Guid("3d8466c1-e406-4e47-b744-6915afe6e003"))
        dockName.DockForm(info, Info1, mode, zDockMode.Outer)
        dockName.SetHeight(info, 310)
    End Sub
    Public Sub Dockbottom(ByVal form As Form, ByVal dockName As DockContainer, ByVal mode As System.Windows.Forms.DockStyle)
        Dim Info1 As DockableFormInfo = dockName.GetFormInfo(New Guid("a6402b80-2ebd-4fd3-8930-024a6201d001"))
        form.Bounds = New Rectangle(700, 100, 200, 450)
        Dim info As DockableFormInfo = dockName.Add(form, zAllowedDock.All, New Guid("0a3f4468-080b-404e-b012-997b93ed2005"))
        dockName.DockForm(info, Info1, mode, zDockMode.Inner)
        dockName.SetHeight(info, 310)
    End Sub

    Public Sub Export(ByVal dataGridview As DataGridView, Optional ByVal str As String = "")
        Try
            Dim objSaveFileDialog As New SaveFileDialog
            With objSaveFileDialog
                .DefaultExt = "xls"
                .FileName = "Excell File"
                .Filter = "Excell File (*.xls)|*.xls|All files (*.*)|*.*"
                .FilterIndex = 1
                .OverwritePrompt = True
                .Title = "Lưu lại file export"
            End With
            Dim filePath As String = ""
            If objSaveFileDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
                Try
                    filePath = System.IO.Path.Combine(My.Computer.FileSystem.SpecialDirectories.MyDocuments, objSaveFileDialog.FileName)
                    Dim file As FileStream
                    Dim writer As StreamWriter
                    Try
                        file = New FileStream(filePath, FileMode.CreateNew)
                        writer = New StreamWriter(file, System.Text.Encoding.Unicode)
                        writer.WriteLine(str)
                        For i As Integer = 0 To dataGridview.Columns.Count - 1
                            If dataGridview.Columns(i).Visible = True Then
                                writer.Write(dataGridview.Columns(i).HeaderText & vbTab)
                            End If
                        Next
                        writer.WriteLine("")
                        For i As Integer = 0 To dataGridview.Rows.Count - 1
                            For j As Integer = 0 To dataGridview.Columns.Count - 1
                                If dataGridview.Columns(j).Visible = True Then
                                    writer.Write(dataGridview.Rows(i).Cells(j).Value.ToString & vbTab)
                                End If

                            Next
                            writer.WriteLine("")
                        Next
                        writer.Close()
                        file.Close()
                    Catch EX As Exception
                    End Try
                Catch fileException As Exception
                    Throw fileException
                End Try
            End If
            'Clean up
            objSaveFileDialog.Dispose()
            objSaveFileDialog = Nothing
        Catch ex As Exception
        End Try
    End Sub

    Public Sub ComboboxComplete(ByVal Combobox As ComboBox)
        Combobox.AutoCompleteMode = AutoCompleteMode.Suggest
        Combobox.AutoCompleteSource = AutoCompleteSource.ListItems
    End Sub

End Module
